<?xml version='1.0' encoding='UTF-8' ?>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

<f:view encoding="ISO-8859-1">
	<h:head>
		<title>Produtos cadastrados</title>
		<h:outputStylesheet library="css" name="styles.css" />
		<h:outputScript library="js" name="scripts.js" />
	</h:head>
	<h:body>
		<h:form id="frmCadProduct" styleClass="frm"
			rendered="#{loginBean.isLogged() and loginBean.hasPermission('CadGeneral')}">
			
			<ui:include src="../../templates/menu.xhtml" />
			
			<p:growl id="messages" showDetail="true" sticky="true"/>
				
			<p:panel id="cadPanelProduct" header="Cadastro de produtos" styleClass="cadPanelPrincipal">
				<h:panelGrid id="panelGrid" columns="4" cellspacing="5">
				
					<h:outputLabel id="lblProductBarcode" value="Código de barras: "
						styleClass="outPutLabel" />
					<p:inputText id="txtProductBarcode" label="Código de barras"
						styleClass="inputText" value="#{productBean.barcode}">
					</p:inputText>
				
					<h:outputLabel id="lblProductName" value="Nome: "
						styleClass="outPutLabel" />
					<p:inputText id="txtProductName" label="Nome"
						styleClass="inputText" value="#{productBean.name}">
					</p:inputText>
					
					<h:outputLabel id="lblProductNumber" value="Número: "
						styleClass="outPutLabel" />
					<p:inputText id="txtProductNumber" label="Número"
						styleClass="inputText" value="#{productBean.proNumber}">
					</p:inputText>
				
					<h:outputLabel id="lblProdPrice" value="Preço: " styleClass="outPutLabel" />
					<p:inputText maxlength="15" size="20" id="txtProdPrice" value="#{productBean.price}"
						styleClass="inputText" label="Preço">
						<f:convertNumber maxFractionDigits="2" groupingUsed="true" currencySymbol="R$"
							maxIntegerDigits="4" type="currency" currencyCode="BRL"/>
					</p:inputText>
					
					<h:outputLabel id="lblProdQtd" value="Quantidade: " styleClass="outPutLabel" />
					<p:inputText id="txtProdQtd" value="#{productBean.receivedQtd}"
						styleClass="inputText" label="Quantidade">
					</p:inputText>
					
					<h:outputLabel id="lblProdDateRec" value="Data de recebimento: "
						styleClass="outPutLabel" />
					<p:calendar id="calProdDateRec" locale="pt_BR" showButtonPanel="true" navigator="true" label="Data de recebimento"
						value="#{productBean.receiptDate}" pattern="dd/MM/yyyy" mindate="#{productBean.currentDate}"/>

					<h:outputLabel id="lblProdCover" value="Capa: "
						styleClass="outPutLabel" />
					<p:inputText id="txtProdCover" value="#{productBean.cover}"
						styleClass="inputText" label="Capa">
					</p:inputText>
					
					<h:outputLabel id="lblProdDistr" value="Distribuidor: "
						styleClass="outPutLabel" />
					<p:selectOneMenu id="selProdDistr" value="#{productBean.dicode}" label="Distribuidor">
						<f:selectItem itemLabel="Selecione o distribuidor" itemValue="" />  
						<f:selectItems value="#{productBean.distributorList}"  var="dis"
							itemValue="#{dis.dicode}" itemLabel="#{dis.person.name}" />
						<p:ajax listener="#{productBean.selDistributorChanged}"/>
					</p:selectOneMenu>
					
					<h:outputLabel id="lblProdPub" value="Editora: "
						styleClass="outPutLabel" />
					<p:selectOneMenu id="selProdPub" value="#{productBean.pucode}" label="Editora">
						<f:selectItem itemLabel="Selecione a editora" itemValue="" />  
						<f:selectItems value="#{productBean.publisherList}"  var="pub"
							itemValue="#{pub.pucode}" itemLabel="#{pub.description}" />
						<p:ajax listener="#{productBean.selPublisherChanged}"/>
					</p:selectOneMenu>
					
					<h:outputLabel id="lblProdGen" value="Gênero: "
						styleClass="outPutLabel" />
					<p:selectOneMenu id="selProdGen" value="#{productBean.gecode}" label="Gênero">
						<f:selectItem itemLabel="Selecione o gênero" itemValue="" />  
						<f:selectItems value="#{productBean.genreList}"  var="gen"
							itemValue="#{gen.gecode}" itemLabel="#{gen.description}" />
						<p:ajax listener="#{productBean.selGenreChanged}"/>
					</p:selectOneMenu>
				</h:panelGrid>
				<p:commandButton id="cmdButtonRegister" value="Cadastrar" actionListener="#{productBean.onRegisterClick}"
					update=":frmCadProduct:tblProducts :frmCadProduct:messages" icon="ui-icon-disk"/>
				
				<p:dataTable id="tblProducts" var="pro" value="#{productBean.productListWhereReturnIsNull}"
					widgetVar="productsTable" filteredValue="#{productBean.filteredProducts}"
					emptyMessage="Não foi encontrado nenhum produto com a característica informada!"
					paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
					paginator="true" rows="10">
					
					<p:column headerText="CÓDIGO" filterBy="#{pro.barcode}"
						filterMatchMode="contains">
						#{pro.barcode}
					</p:column>
					<p:column headerText="NOME" filterBy="#{pro.name}"
						filterMatchMode="contains">
						#{pro.name}
					</p:column>
					<p:column headerText="NÚMERO" filterBy="#{pro.proNumber}"
						filterMatchMode="exact">
						#{pro.proNumber}
					</p:column>
					<p:column headerText="PREÇO">
						<h:outputText value="#{pro.price}">
							<f:convertNumber maxFractionDigits="2" groupingUsed="true" currencySymbol="R$"
								maxIntegerDigits="4" type="currency" currencyCode="BRL"/>
						</h:outputText>
					</p:column>					
				</p:dataTable>
			</p:panel>
		</h:form>
		<h:form	rendered="#{!loginBean.isLogged() or !loginBean.hasPermission('CadGeneral')}">
			<h1 align="center">
				<h:outputText value="Acesso não autorizado a esta página!" />
			</h1>
			<h1 align="center">
				<h:graphicImage value="#{resource['images/general/forbidden.png']}" />
			</h1>
		</h:form>
		<ui:include src="../../templates/footer.xhtml" />
	</h:body>
</f:view>
</html>